## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005
##
##  Extra EventHandlers by primem0ver
##

from CvPythonExtensions import *
import CvUtil
import PyHelpers
import Popup as PyPopup

# globals
gc = CyGlobalContext()
unitCity = None

class  UrbanPlannerHandler:
	def __init__(self):
		self.city = None

	def doUnitLost(self, argsList):
		#print "Running Custom Script"
		unit = argsList[0]
		handleEvent = 0
		if (unit.getUnitType() != gc.getInfoTypeForString("UNIT_URBAN_PLANNER")):
			return
		else:
			#print "Handling urban settler"
			#print self.city
			if (self.city):
				#print "Adding Buildings"
				civ = gc.getPlayer(unit.getOwner()).getCivilizationType()
				
				#Granary class
				eBuilding = gc.getCivilizationInfo(civ).getCivilizationBuildings(gc.getInfoTypeForString("BUILDINGCLASS_GRANARY"))
				if (eBuilding != BuildingTypes.NO_BUILDING):
					self.city.setHasRealBuilding(eBuilding, true)
				else:
					self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_GRANARY"), true)
				
				#Forge class
				eBuilding = gc.getCivilizationInfo(civ).getCivilizationBuildings(gc.getInfoTypeForString("BUILDINGCLASS_FORGE"))
				if (eBuilding != BuildingTypes.NO_BUILDING):
					self.city.setHasRealBuilding(eBuilding, true)
				else:
					self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_FORGE"), true)
				
				#Courthouse class
				eBuilding = gc.getCivilizationInfo(civ).getCivilizationBuildings(gc.getInfoTypeForString("BUILDINGCLASS_COURTHOUSE"))
				if (eBuilding != BuildingTypes.NO_BUILDING):
					self.city.setHasRealBuilding(eBuilding, true)
				else:
					self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_COURTHOUSE"), true)
				
				#Stable class
				eBuilding = gc.getCivilizationInfo(civ).getCivilizationBuildings(gc.getInfoTypeForString("BUILDINGCLASS_STABLE"))
				if (eBuilding != BuildingTypes.NO_BUILDING):
					self.city.setHasRealBuilding(eBuilding, true)
				else:
					self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_STABLE"), true)
				
				#Market class
				eBuilding = gc.getCivilizationInfo(civ).getCivilizationBuildings(gc.getInfoTypeForString("BUILDINGCLASS_MARKET"))
				if (eBuilding != BuildingTypes.NO_BUILDING):
					self.city.setHasRealBuilding(eBuilding, true)
				else:
					self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_MARKET"), true)
				
				#Aqueduct class
				eBuilding = gc.getCivilizationInfo(civ).getCivilizationBuildings(gc.getInfoTypeForString("BUILDINGCLASS_AQUEDUCT"))
				if (eBuilding != BuildingTypes.NO_BUILDING):
					self.city.setHasRealBuilding(eBuilding, true)
				else:
					self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_AQUEDUCT"), true)
				
				#Grocer class
				eBuilding = gc.getCivilizationInfo(civ).getCivilizationBuildings(gc.getInfoTypeForString("BUILDINGCLASS_GROCER"))
				if (eBuilding != BuildingTypes.NO_BUILDING):
					self.city.setHasRealBuilding(eBuilding, true)
				else:
					self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_GROCER"), true)
				self.city.setPopulation(4)
				if (self.city.isCoastal(1)):
					self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_HARBOR"), true)
					self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_LIGHTHOUSE"), true)
		return
		
	def setCity(self, argsList):
		city = argsList[0]
		self.city = city
		#print "City founded: " + city.getName()

	





			
